package com;

import com.common.service.UserService;
import com.ljp.RpcApplication;
import com.ljp.bootstrap.ProviderBootstrap;
import com.ljp.config.RegistryConfig;
import com.ljp.config.RpcConfig;
import com.ljp.model.ServiceMetaInfo;
import com.ljp.model.ServiceRegisterInfo;
import com.ljp.registry.LocalRegistry;
import com.ljp.registry.Registry;
import com.ljp.registry.RegistryFactory;
import com.ljp.server.Server;
import com.ljp.server.tcp.VertxTcpServer;

import java.util.ArrayList;
import java.util.List;

/**
 * 服务提供者示例
 */
public class ProviderExample {

    public static void main(String[] args) {
        //// 本地注册服务
        //String serviceName = UserService.class.getName();
        //LocalRegistry.register(serviceName, UserServiceImpl.class);
        //
        //// 注册服务到注册中心
        //RpcConfig rpcConfig = RpcApplication.getRpcConfig();
        //RegistryConfig registryConfig = rpcConfig.getRegistryConfig();
        //Registry registry = RegistryFactory.getInstance(registryConfig.getRegistry());
        //ServiceMetaInfo serviceMetaInfo = new ServiceMetaInfo();
        //serviceMetaInfo.setServiceName(serviceName);
        //serviceMetaInfo.setServiceHost(rpcConfig.getServerHost());
        //serviceMetaInfo.setServicePort(rpcConfig.getServerPort());
        //try {
        //    registry.register(serviceMetaInfo);
        //} catch (Exception e) {
        //    throw new RuntimeException(e);
        //}
        //
        //// 启动 web 服务
        //Server server = new VertxTcpServer();
        ////HttpServer server = new VertxHttpServer();
        //server.doStart(RpcApplication.getRpcConfig().getServerPort());
        // 要注册的服务
        List<ServiceRegisterInfo<?>> serviceRegisterInfoList = new ArrayList<>();
        ServiceRegisterInfo<UserService> serviceRegisterInfo =
                new ServiceRegisterInfo<>(UserService.class.getName(),
                        UserServiceImpl.class);
        serviceRegisterInfoList.add(serviceRegisterInfo);

        // 服务提供者初始化
        ProviderBootstrap.init(serviceRegisterInfoList);
    }
}
